package com.jia.videos.controller;


import com.jia.videos.common.dto.VideoQuery;
import com.jia.videos.common.dto.VideoSearch;
import com.jia.videos.common.lang.R;
import com.jia.videos.entity.VideoShow;
import com.jia.videos.service.VideoShowService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dujiajia
 * @since 2020-12-21
 */
@RestController
@RequestMapping("/videos/show")
@CrossOrigin
@Api(tags = "视频展示管理")
public class VideoShowController {

    @Autowired
    VideoShowService videoShowService;

    @GetMapping("member")
    public R member() {
        List<VideoShow> list = videoShowService.getMemberList();
        return R.ok().data("data",list);
    }

    @GetMapping("hots")
    public R hots() {
        List<VideoShow> list = videoShowService.getHots();
        return R.ok().data("data",list);
    }

    @GetMapping("queryAll/{keys}")
    public R queryAll(@PathVariable String keys) {
        List<VideoShow> list = videoShowService.queryAll(keys);
        return R.ok().data("data",list);
    }

    @GetMapping("queryList")
    public R queryList(VideoQuery videoQuery) {
        Map<String,Object> map = videoShowService.queryList(videoQuery);
        return R.ok().data(map);
    }

    @GetMapping("list")
    public R list() {
        List<VideoShow> list = videoShowService.list();
        return R.ok().data("data",list);
    }

    @GetMapping("info/{id}")
    public R info(@PathVariable Long id){
        VideoShow detail = videoShowService.getById(id);
        return R.ok().data("data",detail);
    }

    @PostMapping("save")
    public R save(@RequestBody VideoShow videoShow) {
        videoShowService.save(videoShow);
        return R.ok();
    }

    @PutMapping("update")
    public R update(@RequestBody VideoShow videoShow) {
        videoShowService.updateById(videoShow);
        return R.ok();
    }
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Long id){
        videoShowService.removeById(id);
        return R.ok();
    }
}

